package database;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Record implements Serializable, Comparable<Record> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected List<ChangeListener> changeListeners = new ArrayList<ChangeListener>();
	protected int id;
	protected Patient patient;
	protected Doctor doctor;
	protected Nurse nurse;
	protected String data;

	public Record(int id, Patient patient, Doctor doctor, Nurse nurse,
			String data) {
		this.id = id;
		this.patient = patient;
		this.doctor = doctor;
		this.nurse = nurse;
		this.data = data;
	}

	@Override
	public String toString() {
		return "---Record---\n" + "Record ID: \t" + getID() + "\n"
				+ "Doctor: \t" + getDoctor().getName() + "\n" + "Nurse: \t\t"
				+ getNurse().getName() + "\n" + "Patient: \t"
				+ getPatient().getName() + "\n" + "Data: \t\t" + getData()
				+ "\n" + "---End of record---";
	}

	public Patient getPatient() {
		return patient;
	}

	public Doctor getDoctor() {
		return doctor;
	}

	public Nurse getNurse() {
		return nurse;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		for (ChangeListener cl : changeListeners)
			cl.change(this);
		this.data = data;
	}

	public int getID() {
		return id;
	}

	public boolean equals(Record other) {
		return patient.equals(other.patient);
	}

	public void addChangeListener(ChangeListener cl) {
		changeListeners.add(cl);
	}

	public void pendingRemoval() {
		for (ChangeListener cl : changeListeners)
			cl.change(this);
	}

	public int compareTo(Record r) {
		return getID() - r.getID();
	}

}
